import common from './common'

const paths = {
  saveProjectBase: 'projectBase/create',
  getProjectBase: 'projectBase/get',
  saveConstructionUnit: 'projectBase/unit/save',
  saveUnitRelation: 'projectBase/unit/{unitId}/base/{baseId}/relation',
  deleteProjectBaseUnitRelation: 'projectBase/baseUnit/delete',
  getConstructionUnit: 'projectBase/unit/get',
  deleteConstructionUnit: 'projectBase/unit/delete',
  getConstructorUnitInfo: 'projectBase/getConstructorUnitInfo',
  getProjectBaseChangeLog: 'projectBase/data/change/log',
  deleteProjectBaseById: 'projectBase/base/delete',
  createProjectBaseByProjectId: 'projectBase/createProjectBaseByProjectId'
}

const projectBaseService = {};

(function (service) {
  /**
   * 保存：大项目基本信息
   * @param projectBase
   * @returns {Promise | Promise<unknown>}
   */
  service.saveProjectBase = (projectBase) => {
    return common.post(paths.saveProjectBase, null, projectBase)
  }
  /**
   * 获取：大项目基本信息
   * @param baseId
   * @returns {Promise | Promise<unknown>}
   */
  service.getProjectBase = (baseId) => {
    return common.get(paths.getProjectBase, { baseId })
  }
  /**
   * 删除大项目基本信息和关联单位信息
   * @param baseId
   * @returns {Promise | Promise<unknown>}
   */
  service.deleteProjectBaseById = (baseId) => {
    return common.post(paths.deleteProjectBaseById, { baseId }, null)
  }
  /**
   * 保存：建设单位基本信息
   * @param baseId
   * @param constructorUnit
   * @returns {Promise | Promise<unknown>}
   */
  service.saveConstructionUnit = (baseId, constructorUnit) => {
    return common.post(paths.saveConstructionUnit, { baseId }, constructorUnit)
  }
  /**
   * 保存：项目与建设单位关联关系
   * @param unitId
   * @param baseId
   * @returns {Promise | Promise<unknown>}
   */
  service.saveUnitRelation = (baseId, unitId) => {
    return common.post(paths.saveUnitRelation.replace('{unitId}', unitId).replace('{baseId}', baseId), null)
  }
  /**
   * 从大项目中删除建设单位关联
   * @param baseId
   * @param unitId
   * @returns {Promise | Promise<unknown>}
   */
  service.deleteProjectBaseUnitRelation = (baseId, unitId) => {
    return common.get(paths.deleteProjectBaseUnitRelation, { baseId, unitId })
  }
  /**
   * 获取：建设单位基本信息
   * @param unitId
   * @returns {Promise | Promise<unknown>}
   */
  service.getConstructionUnit = (unitId) => {
    return common.get(paths.getConstructionUnit, { unitId })
  }
  /**
   * 删除：建设单位
   * @param unitId 建设单位Id
   * @returns {Promise | Promise<unknown>}
   */
  service.deleteConstructionUnit = (unitId) => {
    return common.get(paths.deleteConstructionUnit, { unitId })
  }
  /**
   * 获取：单位信息
   * @param unitName
   * @returns {Promise | Promise<unknown>}
   */
  service.getConstructorUnitInfo = (unitName) => {
    return common.get(paths.getConstructorUnitInfo, { unitName })
  }
  /**
   * 信息变更日志
   * @param refId
   * @param dataSource
   * @returns {Promise | Promise<unknown>}
   */
  service.getProjectBaseChangeLog = (refId, dataSource) => {
    return common.get(paths.getProjectBaseChangeLog, { refId, dataSource })
  }
  /**
   * 通过projectId创建大项目信息
   * @param projectId
   * @returns {Promise | Promise<unknown>}
   */
  service.createProjectBaseByProjectId = (params) => {
    return common.post(paths.createProjectBaseByProjectId, params)
  }
})(projectBaseService)

export default projectBaseService
